<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>周任务测试</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }
        .container {
            max-width: 1000px;
            margin: 0 auto;
            background: white;
            border-radius: 15px;
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            overflow: hidden;
        }
        .header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 30px;
            text-align: center;
        }
        .content {
            padding: 30px;
        }
        .section {
            margin-bottom: 30px;
            padding: 20px;
            border: 1px solid #e0e0e0;
            border-radius: 10px;
            background: #fafafa;
        }
        .form-group {
            margin-bottom: 15px;
        }
        .form-group label {
            display: block;
            margin-bottom: 5px;
            font-weight: 600;
            color: #555;
        }
        .form-group input, .form-group textarea {
            width: 100%;
            padding: 12px;
            border: 2px solid #ddd;
            border-radius: 8px;
            font-size: 14px;
            transition: border-color 0.3s;
        }
        .btn {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            padding: 12px 25px;
            border-radius: 8px;
            cursor: pointer;
            font-size: 14px;
            font-weight: 600;
            margin-right: 10px;
        }
        .output {
            background: #f8f9fa;
            border: 1px solid #dee2e6;
            border-radius: 8px;
            padding: 15px;
            height: 400px;
            overflow-y: auto;
            font-family: 'Courier New', monospace;
            font-size: 12px;
            white-space: pre-wrap;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>📅 周任务测试</h1>
            <p>测试周任务API功能</p>
        </div>

        <div class="content">
            <div class="section">
                <h2>⚙️ 服务配置</h2>
                <div class="form-group">
                    <label for="baseUrl">服务端地址:</label>
                    <input type="text" id="baseUrl" value="http://localhost:7081" placeholder="请输入服务端地址">
                </div>
                <div class="form-group">
                    <label for="token">认证Token (可选):</label>
                    <input type="text" id="token" placeholder="请输入用户认证Token">
                </div>
            </div>

            <div class="section">
                <h2>📝 周任务内容</h2>
                <div class="form-group">
                    <label for="weekTaskMessage">周任务描述 (支持Markdown格式):</label>
                    <textarea id="weekTaskMessage" rows="12" placeholder="请详细描述周任务内容，支持Markdown格式。

例如：
# 本周工作计划

## 主要任务
- 完成用户位置分析功能开发
- 优化SSE连接稳定性
- 修复已知bug

## 技术目标
- 提升系统性能
- 完善错误处理机制
- 增加单元测试覆盖率

## 时间安排
- 周一至周三：核心功能开发
- 周四：测试和调试
- 周五：文档整理和部署"></textarea>
                </div>
                <div class="controls">
                    <button id="submitBtn" class="btn">提交周任务</button>
                    <button id="clearBtn" class="btn">清空结果</button>
                    <button id="exampleBtn" class="btn">加载示例</button>
                </div>
            </div>

            <div class="section">
                <h2>📊 提交结果</h2>
                <div id="output" class="output">等待提交...</div>
            </div>
        </div>
    </div>

    <script>
        const baseUrlEl = document.getElementById('baseUrl');
        const tokenEl = document.getElementById('token');
        const weekTaskMessageEl = document.getElementById('weekTaskMessage');
        const outputEl = document.getElementById('output');
        const submitBtn = document.getElementById('submitBtn');
        const clearBtn = document.getElementById('clearBtn');
        const exampleBtn = document.getElementById('exampleBtn');

        function init() {
            submitBtn.addEventListener('click', submitWeekTask);
            clearBtn.addEventListener('click', clearOutput);
            exampleBtn.addEventListener('click', loadExample);
            
            // 设置默认值
            tokenEl.value = 'test-token-123';
        }

        async function submitWeekTask() {
            const message = weekTaskMessageEl.value.trim();
            const token = tokenEl.value.trim();
            const baseUrl = baseUrlEl.value.trim();
            
            if (!message) {
                alert('请输入周任务描述');
                return;
            }
            
            try {
                submitBtn.disabled = true;
                clearOutput();
                
                const requestData = { 
                    message: message
                };
                
                // 构建URL，如果有token则添加到URL参数中
                let url = `${baseUrl}/api/client/index/addWeekTask`;
                if (token) {
                    url += `?token=${encodeURIComponent(token)}`;
                }
                
                const response = await fetch(url, {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify(requestData)
                });
                
                if (!response.ok) {
                    throw new Error(`HTTP ${response.status}: ${response.statusText}`);
                }
                
                const result = await response.json();
                
                if (result.code === 200) {
                    appendOutput('提交成功:\n');
                    appendOutput(JSON.stringify(result.data, null, 2));
                } else {
                    throw new Error(result.message || '提交失败');
                }
                
            } catch (error) {
                appendOutput(`错误: ${error.message}`);
            } finally {
                submitBtn.disabled = false;
            }
        }
        
        function clearOutput() {
            outputEl.textContent = '';
        }
        
        function appendOutput(content) {
            outputEl.textContent += content;
            outputEl.scrollTop = outputEl.scrollHeight;
        }

        function loadExample() {
            const exampleText = `# 本周工作计划

## 主要任务
- 完成用户位置分析功能开发
- 优化SSE连接稳定性
- 修复已知bug

## 技术目标
- 提升系统性能
- 完善错误处理机制
- 增加单元测试覆盖率

## 时间安排
- 周一至周三：核心功能开发
- 周四：测试和调试
- 周五：文档整理和部署`;
            
            weekTaskMessageEl.value = exampleText;
        }

        document.addEventListener('DOMContentLoaded', init);
    </script>
</body>
</html> 